package com.hele.sts.pub;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SqlQuery
{
  Connection cn;
  ConnectDB connsyb;
  ResultSet rs;
  Statement st;
  
  public SqlQuery(String dataS)
  {
    this.cn = null;
    this.st = null;
    this.rs = null;
    ConnectDB connsyb = SpringContextHolder.getBean(ConnectDB.class);
    try {
		this.cn = connsyb.getConnection();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
  }
  
  public SqlQuery()
  {
    this.cn = null;
    this.st = null;
    this.rs = null;
    ConnectDB connsyb = SpringContextHolder.getBean(ConnectDB.class);
    try {
		this.cn = connsyb.getConnection();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
  }
  
  public Exception close()
    throws SQLException
  {
    if (this.rs != null) {
      this.rs.close();
    }
    if (this.st != null) {
      this.st.close();
    }
    if (this.cn != null) {
      this.cn.close();
    }
    try
    {
      if (this.st != null) {
        this.st.close();
      }
      if (this.cn != null) {
        this.cn.close();
      }
    }
    catch (Exception localException1) {}
    try
    {
      if (this.rs != null) {
        this.rs.close();
      }
    }
    catch (SQLException _ex2)
    {
      try
      {
        if (this.st != null) {
          this.st.close();
        }
      }
      catch (SQLException localSQLException1) {}
      try
      {
        if (this.cn != null) {
          this.cn.close();
        }
      }
      catch (SQLException localSQLException2) {}
    }
    try
    {
      if (this.st != null) {
        this.st.close();
      }
    }
    catch (SQLException _ex2)
    {
      try
      {
        if (this.cn != null) {
          this.cn.close();
        }
      }
      catch (SQLException localSQLException3) {}
    }
    try
    {
      if (this.cn != null) {
        this.cn.close();
      }
    }
    catch (SQLException localSQLException4) {}
    try
    {
      if (this.st != null) {
        this.st.close();
      }
      if (this.cn != null) {
        this.cn.close();
      }
    }
    catch (Exception localException2) {}
    Exception exception = null;
    try
    {
      if (this.st != null) {
        this.st.close();
      }
      if (this.cn != null) {
        this.cn.close();
      }
    }
    catch (Exception localException3) {}
    return exception;
  }
  
  public ResultSet getResultSetGxdw(String strsql, String userid)
    throws SQLException
  {
    PreparedStatement pr = this.cn.prepareStatement(strsql);
    pr.setString(1, userid);
    this.rs = pr.executeQuery();
    return this.rs;
  }
  
  public String getResultSetDyqx(String strsql, String userid)
    throws SQLException
  {
    PreparedStatement pr = this.cn.prepareStatement(strsql);
    pr.setString(1, userid);
    this.rs = pr.executeQuery();
    if (this.rs.next())
    {
      String dyqx = this.rs.getString("dyqx").toString();
      return dyqx;
    }
    return "0";
  }
  
  public ResultSet getResultSet(String strsql)
    throws SQLException
  {
    this.st = this.cn.createStatement(1004, 1008);
    this.rs = this.st.executeQuery(strsql);
    return this.rs;
  }
  
  public ResultSet getResultSet(String strsql, String arg1, String arg2)
    throws SQLException
  {
    PreparedStatement pr = this.cn.prepareStatement(strsql);
    pr.setString(1, arg1);
    pr.setString(2, arg2);
    this.rs = pr.executeQuery();
    return this.rs;
  }
}
